<?php

namespace mpend\modules\team\controllers;

use Yii;
use mpend\components\Controller;
use mpend\modules\team\models\TeamBookMemberDateSearch;
use mpend\modules\team\models\BookDashboardLogic;
use common\logics\WorkbookLogic;

/**
 * 记工本详情管理
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class BookController extends Controller {

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            '*' => ['GET']
        ];
    }

    /**
     * @inheritdoc
     */
    public function actionMonth($id, $date = null) {
        $model = new BookDashboardLogic();
        $model->setToken($this->token);
        $model->workbook_id = $id;
        $model->date = $date;
        return $model->toArray();
    }

    /**
     * @inheritdoc
     */
    public function actionDate($id, $date = null) {
        $workbook = WorkbookLogic::findOrFail($id);
        $model = new TeamBookMemberDateSearch();
        $model->pagesize = false;
        $model->workbook_id = $workbook->id;
        $model->setExtraAttributes([
            'date' => $date,
        ]);
        if (!$workbook->hasSuperviseControl($this->uid)) {
            $model->user_id = $this->uid;
        }
        return $model->search();
    }

}
